﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace DLL.Training
{
	/// <summary>
	/// 视图控制类
	/// </summary>
	/// <![CDATA[2014-8-7 17:52:59]]>
	public class View : DLL.ShowLayer.FormView
	{
		private Component clsthisComp;

		#region 添加、修改
		private DropDownList ddlSort = new DropDownList();
		private TextBox tbName = new TextBox();
		private DropDownList ddlDepartment = new DropDownList();
		private TextBox tbStartDate = new TextBox();
		private TextBox tbEndDate = new TextBox();
		private TextBox tbTeachers = new TextBox();
		private DropDownList ddlType = new DropDownList();
		//private AjaxControlToolkit.CalendarExtender ajaxStartDate = new AjaxControlToolkit.CalendarExtender();
		//private AjaxControlToolkit.CalendarExtender ajaxEndDate = new AjaxControlToolkit.CalendarExtender();
		//private AjaxControlToolkit.ToolkitScriptManager ajaxManager = new AjaxControlToolkit.ToolkitScriptManager();
		/// <summary>
		/// 培训地点
		/// </summary>
		private TextBox tbAddress = new TextBox();
		/// <summary>
		/// 培训内容
		/// </summary>
		private TextBox tbContent = new TextBox();
		/// <summary>
		/// 培训机构
		/// </summary>
		private DropDownList ddlTrainingOrganization = new DropDownList();
		#endregion 添加、修改

		#region 查询
		private TextBox tbQueryStartDate = new TextBox();
		private TextBox tbQueryEndDate = new TextBox();
		//private AjaxControlToolkit.CalendarExtender ajaxQueryStartDate = new AjaxControlToolkit.CalendarExtender();
		//private AjaxControlToolkit.CalendarExtender ajaxQueryEndDate = new AjaxControlToolkit.CalendarExtender();
		private DropDownList ddlQuerySort = new DropDownList();
		private TextBox tbQueryName = new TextBox();
		private DropDownList ddlQueryState = new DropDownList();
		private DropDownList ddlQueryDepartment = new DropDownList();
		private TextBox tbQueryTeachers = new TextBox();
		#endregion 查询

		#region 浏览

		#endregion 浏览

		#region 构造函数
		/// <summary>
		/// 视图类构造函数
		/// </summary>
		/// <![CDATA[2014-8-24 14:17:16]]>
		public View(System.Web.UI.Page page)
			: base(page)
		{
			clsthisComp = new Component(page);

			clsComp = clsthisComp;

			//ajaxManager.EnableScriptGlobalization = true;
			//ajaxManager.EnableScriptLocalization = true;

			tbStartDate.ID = "201409101118";
			tbStartDate.Text = System.DateTime.Now.ToShortDateString();
			tbEndDate.ID = "201409120858";
			tbEndDate.Text = System.DateTime.Now.ToShortDateString();
			tbStartDate.Attributes.Add("onClick", "popUpCalendar(this, this, 'yyyy-mm-dd')");
			tbEndDate.Attributes.Add("onClick", "popUpCalendar(this, this, 'yyyy-mm-dd')");
			//ajaxStartDate.TargetControlID = tbStartDate.ID;
			//ajaxEndDate.TargetControlID = tbEndDate.ID;

			clsControls.ShowTrainingSort(ddlSort);
			clsControls.ShowDepartment(ddlDepartment);
			clsControls.ShowTrainingType(ddlType);
			clsControls.ShowTrainingOrganization(ddlTrainingOrganization);
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("类别", "DropDownList", ddlSort, "int", "nSortID"));
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("培训名称", "TextBox", tbName, "string", "strName"));
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("培训地点", "TextBox", tbAddress, "string", "strAddress"));
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("培训内容", "TextBox", tbContent, "string", "strContent"));
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("组织部门", "DropDownList", ddlDepartment, "int", "nDepartmentID"));
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("培训机构", "DropDownList", ddlTrainingOrganization, "int", "nOrganizationID"));
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("培训开始时间", "TextBox", tbStartDate, "string", "strStartDate"));
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("培训结束时间", "TextBox", tbEndDate, "string", "strEndDate"));
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("培训教师", "TextBox", tbTeachers, "string", "strTeachers"));
			//listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("培训类型", "DropDownList", ddlType, "int", "nType"));

			tbQueryStartDate.ID = "201409142211";
			tbQueryEndDate.ID = "201409142212";
			//tbQueryStartDate.Text = System.DateTime.Now.ToShortDateString();
			//tbQueryEndDate.Text = System.DateTime.Now.ToShortDateString();
			//ajaxQueryStartDate.TargetControlID = tbQueryStartDate.ID;
			//ajaxQueryEndDate.TargetControlID = tbQueryEndDate.ID;
			tbQueryStartDate.Attributes.Add("onClick", "popUpCalendar(this, this, 'yyyy-mm-dd')");
			tbQueryEndDate.Attributes.Add("onClick", "popUpCalendar(this, this, 'yyyy-mm-dd')");
			clsControls.ShowTrainingSortWithAll(ddlQuerySort);
			clsControls.ShowTrainingStateWithAll(ddlQueryState);
			clsControls.ShowDepartmentWithAll(ddlQueryDepartment);
			listQuery.Add(new TonyNet4V1.Structs.TitleControlEntity("培训类型", "DropDownList", ddlQuerySort, "int", "nSort"));
			listQuery.Add(new TonyNet4V1.Structs.TitleControlEntity("名称", "TextBox", tbQueryName, "string", "strName"));
			listQuery.Add(new TonyNet4V1.Structs.TitleControlEntity("组织单位", "DropDownList", ddlQueryDepartment, "int", "nDepartmentID"));
			listQuery.Add(new TonyNet4V1.Structs.TitleControlEntity("教师", "TextBox", tbQueryTeachers, "string", "strTeachers"));
			listQuery.Add(new TonyNet4V1.Structs.TitleControlEntity("开始日期", "TextBox", tbQueryStartDate, "string", "strQueryStartDate"));
			listQuery.Add(new TonyNet4V1.Structs.TitleControlEntity("结束日期", "TextBox", tbQueryEndDate, "string", "strQueryEndDate"));
			listQuery.Add(new TonyNet4V1.Structs.TitleControlEntity("进度", "DropDownList", ddlQueryState, "int", "nState"));
		}
		#endregion 构造函数

		#region 类型转换

		protected override TonyNet4V1.EntityBase GetEntity()
		{
			return new Entity();
		}

		protected override TonyNet4V1.QueryEntityBase GetQuery()
		{
			return new QueryEntity();
		}

		protected override TonyNet4V1.ComponentBase GetComponent()
		{
			return clsthisComp;
		}

		#endregion 类型转换

		public override void AddEditLayout(Panel pPanel)
		{
			base.AddEditLayout(pPanel);

			//pPanel.Controls.Add(ajaxManager);
			//pPanel.Controls.Add(ajaxStartDate);
			//pPanel.Controls.Add(ajaxEndDate);
		}

		public override void QueryLayout(Panel pPanel)
		{
			base.QueryLayout(pPanel);

			
			//pPanel.Controls.Add(ajaxQueryStartDate);
			//pPanel.Controls.Add(ajaxQueryEndDate);
		}

		public override bool Query(GridView gv)
		{
			QueryEntity clsTrainingQuery = new QueryEntity();

			ControlToQuery(clsTrainingQuery, listQuery);

			if (bQueryByUserID)
			{
				clsTrainingQuery.nUserID = nUserID;
			}

			if (tbQueryName.Text == "")
			{
				clsTrainingQuery.strName = clsTrainingQuery.strAll;
			}
			if (tbQueryStartDate.Text == "")
			{
				//tbQueryStartDate.Text = new TonyNet4V1.QueryEntityBase().strAll;
				clsTrainingQuery.strQueryStartDate = clsTrainingQuery.strAll;
			}

			if (tbQueryEndDate.Text == "")
			{
				//tbQueryEndDate.Text = new TonyNet4V1.QueryEntityBase().strAll;
				clsTrainingQuery.strQueryEndDate = clsTrainingQuery.strAll;
			}

			//bReturn = base.Query(gv);

			gv.DataSource = clsthisComp.Query(clsTrainingQuery);
			gv.DataKeyNames = new string[] { "ID" };
			gv.DataBind();

			return true;
		}

		/// <summary>
		/// 添加
		/// </summary>
		/// <returns></returns>
		public override bool Add()
		{
			Entity clsAddTraining = new Entity();

			ControlToEntity(clsAddTraining, listAddEdit);

			clsAddTraining.UserID = nUserID;
			clsAddTraining.UserDepartmentID = nDepartmentID;

			return clsthisComp.Add(clsAddTraining);
		}
		/// <summary>
		/// 查询本帐号添加的记录，并用GridView显示
		/// </summary>
		/// <param name="gv"></param>
		/// <returns></returns>
		public bool ShowMySelf(GridView gv)
		{
			gv.DataSource = clsthisComp.QueryMySelfTraining(nUserID);
			gv.DataKeyNames = new string[] { "ID" };
			gv.DataBind();

			return true;
		}
	}
}
